package com.example.wallpaperapp.ui.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wallpaperapp.R;
import com.example.wallpaperapp.adapter.HomeRecyclerViewAdapter;
import com.example.wallpaperapp.base.BaseFragment;
import com.example.wallpaperapp.bean.HomeImageRecyclerViewBean;
import com.example.wallpaperapp.ui.activity.Activity_preview;
import com.example.wallpaperapp.utils.RecyclerViewSpacesItemDecoration;
import com.example.wallpaperapp.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;


public class NewestFragment extends BaseFragment {
    private RecyclerView near_recyclerview;
    private List<HomeImageRecyclerViewBean> list = new ArrayList<>();


    @Override
    protected void initView(View view) {
        list.add(new HomeImageRecyclerViewBean("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1852912712,1420753138&fm=26&gp=0.jpg"));
        list.add(new HomeImageRecyclerViewBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2033127995,219501725&fm=26&gp=0.jpg"));
        list.add(new HomeImageRecyclerViewBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2956447936,1596567851&fm=11&gp=0.jpg"));
        list.add(new HomeImageRecyclerViewBean("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3903811193,3056469345&fm=26&gp=0.jpg"));
        list.add(new HomeImageRecyclerViewBean("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1796155707,3592414587&fm=15&gp=0.jpg"));
        list.add(new HomeImageRecyclerViewBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=50824169,1693316958&fm=11&gp=0.jpg"));
        near_recyclerview = view.findViewById(R.id.new_recycler);
        near_recyclerview.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
        near_recyclerview.addItemDecoration(new RecyclerViewSpacesItemDecoration(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION,30));
        HomeRecyclerViewAdapter adapter = new HomeRecyclerViewAdapter(getContext(),list);
        adapter.setOnItemCickListener(new HomeRecyclerViewAdapter.MyOnItemClickListener() {
            @Override
            public void myOnItemClickListener(int position, View view) {
                Activity_preview.startActivity_preview(getActivity(), list.get(position).getImage_url());

                ToastUtil.makeText(getActivity(),"点击了第" + position + "条");
            }
        });
        near_recyclerview.setAdapter(adapter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_newest;
    }

    @Override
    protected void initData(Context context) {

    }

    @Override
    public void onClick(View v) {

    }
}